@extends('home.personal.userlayout')
@section('title','提现')
@section('style')
    <link rel="stylesheet" href="{{ asset('/home/css/tixian.css')}}?version=3"/>
@endsection
@section('content')
    <form action="{{url('tixian_post')}}" id="form" method="post" enctype="multipart/form-data">
        {{ csrf_field() }}
        <input type="hidden" name="uid" value="{{$user->id}}" readonly>
        <div class="l1">
            <input type="text" name="name" value="{{$user->name}}" >
        </div>
        <div class="l1">
            <input type="text" name="mobile" value="{{$user->mobile}}" readonly>
        </div>
        <div class="l1">
            <input type="text" name="money" placeholder="请输入提现金额">
        </div>
        <p class="feilv">额外扣除￥0元手续费（费率为10%）</p>
        <div class="tixianma"  style="display: none;" >
            <img src="" alt="" class="show_img">
            <input type="hidden" name="img" value="">
        </div>
        <input type="file" name="course_imgs" class="upload" id="upload"  onchange="sc(this);" style="display: none;">
        <div class="fileupload" onclick="upload.click()">上传收款码</div>
        <button type="button" class="submit">立即提现</button>
    </form>

@endsection

@section('script')
    <script>
        function sc() {
            var formData = new FormData();
            var img = document.getElementById('upload');
            var fileObj = img.files[0];
            formData.append('course_imgs',fileObj);
            $.ajax({
                url:"{{ url('admin/upload_img') }}",
                type:'post',
                data:formData,
                async:false,
                contentType : false,
                processData : false,
                success:function (data) {
                    $('input[name=img]').val(data.url);
                    $('.tixianma').show();
                    $('.show_img').attr('src',data.url);
                },
                error:function () {
                    console.log('no')
                },
                dataType:'json'

            })
        }
        $('.submit').click(function () {
            var money =  $('input[name=money]').val();
            if(money < 100){
                alert('提现金额大于100元才能提取');
                return false;
            }
            var img =  $('input[name=img]').val();
            if(img == ''){
                alert('请上传收款码');
                return false;
            }
            $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/tixian_post" ,//url
                data: $('#form').serialize(),
                success: function (result) {
                    console.log(result);//打印服务端返回的数据(调试用)
                    alert(result.message);
                    if (result.code == 0) {
                        window.location.href = "{{ url('personal') }}";
                    }
                },
                error : function() {
                    alert("异常！");
                }
            });
        })


    </script>

@endsection